import coin.exchange.base.kr_rest.native_public_client_base as npubcb
from coin.exchange.bithumb.kr_rest.currency import (
    validate_currency, validate_currency_all)


class BithumbNativePublicClient(npubcb.NativePublicClientBase):
  def __init__(self):
    npubcb.NativePublicClientBase.__init__(self, url="https://api.bithumb.com/public")

  def get_ticker(self, order_currency, payment_currency='KRW'):
    validate_currency_all(order_currency)
    validate_currency(payment_currency)
    return self._get_as_json("ticker/%s_%s" % (order_currency, payment_currency))

  def get_orderbook(self, order_currency, payment_currency='KRW'):
    validate_currency(order_currency)
    validate_currency(payment_currency)
    return self._get_as_json("orderbook/%s_%s" % (order_currency, payment_currency))

  def get_recent_transactions(self, order_currency, payment_currency='KRW'):
    validate_currency_all(order_currency)
    validate_currency(payment_currency)
    return self._get_as_json("recent_transactions/%s_%s" % (order_currency, payment_currency))

  def get_history_kline(self, interval, order_currency, payment_currency='KRW'):
    return self._get_as_json("candlestick/%s_%s/%s" % (order_currency, payment_currency, interval))

  def queryAll(self, order_currency, payment_currency='KRW'):
    ticker = self.get_ticker(order_currency, payment_currency)
    orderbook = self.get_orderbook(order_currency, payment_currency)
    transactions = self.get_recent_transactions(order_currency, payment_currency)
    return ticker, orderbook, transactions
